package com.hymjweb.demo.hymj.system_maintenance.user_role.controller;

import com.hymjweb.demo.framework.sys.BaseController;
import com.hymjweb.demo.hymj.system_maintenance.user_role.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/pages/system_maintain/user_role")
public class UserRoleController extends BaseController {

    @Autowired
    private UserRoleService userRoleService;

    @RequestMapping("/queryUserListByRoleId")
    @ResponseBody
    public Object queryUserListByRoleId(@RequestParam(required = false) Map param) {
        return userRoleService.queryUserListByRoleId(param);
    }

    @RequestMapping("/queryUnselectedRoleUser")
    @ResponseBody
    public Object queryUnselectedRoleUser(@RequestParam(required = false) Map param) {
        return userRoleService.queryUnselectedRoleUser(param);
    }

    @RequestMapping("/querySelectedRoleUser")
    @ResponseBody
    public Object querySelectedRoleUser(@RequestParam(required = false) Map param) {
        return userRoleService.querySelectedRoleUser(param);
    }

    @RequestMapping("/saveRoleUser")
    @ResponseBody
    public Object saveRoleUser(@RequestBody Map<String, Object> param) throws Exception {
        if (param == null || param.isEmpty()) {
            throwException("保存用户角色参数错误!");
        }
        return userRoleService.saveRoleUser(param);
    }

    @RequestMapping("/deleteRoleUser")
    @ResponseBody
    public Object deleteRoleUser(@RequestBody Map<String, Object> param) throws Exception {
        if (param == null || param.isEmpty()) {
            throwException("删除用户角色参数错误!");
        }
        return userRoleService.deleteRoleUser(param);
    }
}
